<?php

class Validate_Authenticated extends Zend_Validate_Abstract
{
	/**
	 * @var string
	 */
    const NOT_AUTH = 'not_auth';

	/**
	 * Error messages.
	 *
	 * @var array
	 */
    protected $_messageTemplates = array(
        self::NOT_AUTH => "Вы должны залогиниться перед выполнением данного действия"
    );


    /**
     * Check for user Authenticated with Zend_Auth.
     * ---
     * Returns true if and only if $value meets the validation requirements
     *
     * If $value fails validation, then this method returns false, and
     * getMessages() will return an array of messages that explain why the
     * validation failed.
     *
     * @param  mixed $value
     * @return boolean
     * @throws Zend_Valid_Exception If validation of $value is impossible
     */
    public function isValid($value)
    {
        $this->_setValue('dummy');

        if (!Auth::getInstance()->getProfile()) {
            $this->_error();
            return false;
        }

        return true;
    }
}